package data.set.adaptator;

import java.util.Iterator;

import algorithm.Classifier;

import data.set.OfflineSet;
import data.set.OfflineSetIterator;


/**
 * This class describes a set build with a label from a classifier
 * @author denoyer
 *
 */
public class OfflineSet_To_OfflineSetUsingClassifier<X,Y> implements OfflineSet<Y>
{
	private Classifier<X,Y> machine;
	private OfflineSet<X> set;
	
	public OfflineSet_To_OfflineSetUsingClassifier(Classifier<X,Y> machine,OfflineSet<X> set)
	{
		this.machine=machine;
		this.set=set;
	}
	
	
	public Y getObject(int id) 
	{
		X x=set.getObject(id);
		return(machine.map(x));
	}

	
	public OfflineSetIterator<Y> inputsetiterator() {
		return(new IT(set.inputsetiterator()));
	}

	
	public long size() 
	{
		return(set.size());
	}
 
	
	public Iterator< Y> iterator() {
		return(new Iterator_FromOfflineSetIterator<Y>(inputsetiterator()));
	}

	private class IT implements OfflineSetIterator<Y>
	{
		private OfflineSetIterator<X> it;
		
		public IT(OfflineSetIterator<X> it)
		{
			this.it=it;
		}

		
		public int getCurrentId() {
			return it.getCurrentId();
		} 

		
		public  Y getCurrentObject() {
			X x=it.getCurrentObject();
			return machine.map(x);
		}

		
		public boolean hasNext() {
			return it.hasNext();
		}

		
		public void next() {
			it.next();
		}
	}
}
